#lang scheme

(require
 (lib "1.ss" "srfi")
 "utils.scm")

(provide next-linus-symbol)


(define (next-linus-symbol l a)
  (printd "basing next symbol on history ~s~n" l)
  (let ((s (for/list
            ([l (for/list ([e a]) (cons e (reverse l)))])
            (find (lambda (n) (equal? (take l n) (take (drop l n) n)))
                  (reverse (iota (+ 1 (quotient (length l) 2))))))))
    (list-ref a (list-index (lambda (x) (eq? x (apply min s))) s))))
